<?php

class ConfigController extends GenesisController
{


    public function unpackersAction()
    {
    	/* @var $fileConfig Zend_Config */
    	$filesConfig = $this->_registry->files_config;
        
    	$files=$filesConfig->toArray();
    	
        $changedSomething=false;
        
        $data=array();
        
        foreach (array_keys($files) as $file) {
        	$location=trim($filesConfig->$file->location);
        	if (trim($location) == '') {
        		if (DIRECTORY_SEPARATOR == '/')
                                $location=trim(`which $file`);
                        else
                            $location=$file;
                }
        	if ($location) {
        		$filesConfig->$file->location=$location;
        		$changedSomething=true;
        	}
        	$res=array();        	
        	$res['location']=$location;
        	$res['found']=strlen(trim($location)) > 0 && is_file($location);        	
        	$res['executable']=$res['found'] || is_executable($location); 
        	$data[$file]=$res;
        }
        
        if ($changedSomething) {
        	$writer = new Zend_Config_Writer_Ini(array('config'=>$filesConfig,'filename'=>APPLICATION_PATH . '/configs/files.ini'));
        	$writer->write();
        }
        
    	$this->view->options=$data;
    }

    public function firstConfigAction() {

        $saveIniFile=realpath(__DIR__.DIRECTORY_SEPARATOR.'..').DIRECTORY_SEPARATOR.'configs'.DIRECTORY_SEPARATOR.'application.ini';
        $config = new Zend_Config_Ini($saveIniFile,null,array('skipExtends'        => true,
                                                                'allowModifications' => true));
        $config->production->installation->done=true;
        $writer = new Zend_Config_Writer_Ini(array('config'=>$config,'filename'=>$saveIniFile));
        $writer->write();
    }


}

